define([
    "app"
], function (app) {
    app.controller("signFileController", [
        "$scope",
        "$state",
        "signFileDataService",
        function ($scope, $state, signFileDataService) {

            $scope.state = 'loading';

            signFileDataService
                .getAllTeamNeedToSignFile()
                .then(
                    function success(resp) {
                        $scope.state = 'finished';

                        $scope.teams = resp.data;

                        $scope.submit = function (team) {
                            if(!confirm("确定该团队已经签署了所需文件?")) {
                                return;
                            }

                            signFileDataService
                                .signFileDone(team.teamId)
                                .then(
                                    function success(resp) {
                                        $state.go($state.current, {}, {reload: true});
                                    },
                                    function error(resp) {
                                        alert("似乎出了点问题!!!∑(ﾟДﾟノ)ノ");
                                        $state.go($state.current, {}, {reload: true});
                                    }
                                )
                        }
                    },
                    function error(resp) {
                        $scope.state = 'error';
                    }
                )
        }
    ])
});